'use strict';
const Controller = require('egg').Controller;
class HomeController extends Controller {
  async render() {
    const { ctx } = this;
    var {start,limit} = ctx.query;
    var data = await ctx.service.top250.find({start,limit})
    // var host = ctx.request.header.host
    // console.log(data)
    var result = data.res
    // console.log(result)//123456
    var next = data.next;//2
    // console.log(next)
    var previous = data.previous;
    // console.log(previous)
    var res = data.data
    // console.log(res)

    await ctx.render('index.html', { res, result, next, previous})
  }
  async top250() {
    const { ctx } = this;
    // console.log(this.app.config.jwt.secret)
    var {start,limit} = ctx.query;

    if(start==undefined){
      start = 0
    }
    if(limit ==undefined){
        limit = 5
    }
    var data = await ctx.service.top250.find({start,limit})
    // var total = await ctx.service.top250.find({}).count()
    ctx.body={
      res:data.data,
      // total
    }
  }
  async article() {
    const { ctx } = this;
    var data2 = await ctx.model.Article.find({})
    ctx.body={
      res:data2
    }
  }
}
module.exports = HomeController;